/**
 * Created by vincent on 2017/9/14.
 */
moduleStudyMap.controller("EditStudyClassGroupController", function ($$CambioConfig, $scope, $log, $state, LoadingService, UploadFileService,
                                                                     ConstantService, DialogService, StudyClassGroupResource) {
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
        $scope.editingClassGroup = angular.copy($scope.currentClassGroup);
    });

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.uploadImage = function ($files) {
        if ($files && $files[0]) {
            UploadFileService.uploadFile($files[0], $$CambioConfig.UPLOAD_URL, 'IMG', $scope).then(function (o) {
                $scope.editingClassGroup.picture = o.id;
            });
        }
    };

    $scope.submit = function () {
        if ($scope.editSCGForm.$valid) {
            //LoadingService.show();
            StudyClassGroupResource.update($scope.editingClassGroup, function (groupResult) {
                angular.copy(groupResult, $scope.currentClassGroup);
                $log.debug("章节更新结果", groupResult);
                DialogService.close();
                //LoadingService.hide();
                Alert.success("章节更新成功！");
            });
        }
    };

});